package com.atlzk.group.tgou.controller;

import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Date;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.atlzk.common.utils.FileBlobUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.atlzk.group.tgou.entity.TgouEntity;
import com.atlzk.group.tgou.service.TgouService;
import com.atlzk.common.utils.PageUtils;
import com.atlzk.common.utils.R;
import org.springframework.web.multipart.MultipartFile;


/**
 * 团购活动表
 *
 * @author liuzekun
 * @email 2803587841@gmail.com
 * @date 2021-06-18 17:30:56
 */
@RestController
@RequestMapping("tgou/tgou")
public class TgouController {
    @Autowired
    private TgouService tgouService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("tgou:tgou:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tgouService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{smsTgouId}")
    //@RequiresPermissions("tgou:tgou:info")
    public R info(@PathVariable("smsTgouId") Long smsTgouId){
		TgouEntity tgou = tgouService.getById(smsTgouId);

        return R.ok().put("tgou", tgou);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("tgou:tgou:save")
    public R save(@RequestBody TgouEntity tgou){
        tgou.setSmsTgouCreateDate(new Date());
        tgou.setSmsIsShow(1);
		tgouService.save(tgou);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("tgou:tgou:update")
    public R update(@RequestBody TgouEntity tgou){

		tgouService.updateById(tgou);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("tgou:tgou:delete")
    public R delete(@RequestBody Long[] smsTgouIds){
		tgouService.removeByIds(Arrays.asList(smsTgouIds));

        return R.ok();
    }

    /**
     * 信息
     */
    @RequestMapping("/byId")
    //@RequiresPermissions("tgou:tgou:info")
    public R byId( @RequestParam("smsTgouId") Long smsTgouId){
        TgouEntity tgou = tgouService.getById(smsTgouId);
        return R.ok().put("tgou", tgou);
    }

    @RequestMapping("/byTgouId")
    //@RequiresPermissions("tgou:tgou:info")
    public TgouEntity byTgouId( @RequestParam("smsTgouId") Long smsTgouId){
        TgouEntity tgou = tgouService.getById(smsTgouId);
        return tgou;
    }

    @RequestMapping("/uploadFile")
    public String uploadFile(MultipartFile file) {
        String s = "";
        try {
             s = FileBlobUtil.uploadFile(file);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return s;
    }



}
